Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eastron SDM120 energy meter - new sensor #2694

Closed
wants to merge 25 commits into from
Closed

Eastron SDM120 energy meter - new sensor #2694

wants to merge 25 commits into from

Conversation

gtortone
Copy link
Contributor

@gtortone gtortone commented May 11, 2018

Hi,
I just finished integration of Eastron SDM120 energy meter (http://www.eastrongroup.com/productsview/14.html);

please skip my VS Code setup files included in this PR...

Regards,
Gennaro

gtortone and others added 25 commits December 27, 2017 22:55
@gtortone
Copy link
Contributor Author

sdm120-home
sdm120-config

@altelch
Copy link
Contributor

altelch commented May 11, 2018 via email

@gtortone
Copy link
Contributor Author

gtortone commented May 11, 2018

Hi @altelch I use this RS485<->TTL adapter

rs485-ttl

  • on ESP side I connect TX, RX, GND, +3.3V (ESP power the adapter)
  • on meter I connect A, B, GND

@arendst arendst added the enhancement Type - Enhancement that will be worked on label May 11, 2018
@arendst
Copy link
Owner

arendst commented May 11, 2018

Thnx Gennaro!! Even my latest serial changes are incorporated!

Will release soon.

@gtortone
Copy link
Contributor Author

yes, also Amazon says RS485 to TTL but it is wrong... they mount MAX785 IC that is a RS485 to RS422 (like RS232 but differential)

@rflx18
Copy link

rflx18 commented May 21, 2018

can you please share a link of one i can purchase, darn another month waiting :(

@rflx18
Copy link

rflx18 commented May 21, 2018

another strange thing, i tried to ground the RE to make it low to be alwaysing receiving, ant the tasmota send the command to retrieve power but says unknow command!

in the SDM energy meter github i found this
#define DERE_PIN NOT_A_PIN //digital pin for control MAX485 DE/RE lines (connect DE & /RE together to this pin)
but thjat would mean really help from the masters of tasmota to integrate a new pin to the module to control the DE/RE

@gtortone
Copy link
Contributor Author

take into account that RS422 has +6V/-6V levels (https://en.wikipedia.org/wiki/RS-422) instead UART-TTL has 0V-3.3V... I suggest you to disconnect this adapter because there is a risk to damage RX/TX pins of ESP

@gtortone
Copy link
Contributor Author

gtortone commented May 21, 2018

@rflx18
Copy link

rflx18 commented May 21, 2018

here is the log i was saying
unkown

@rflx18
Copy link

rflx18 commented May 23, 2018

hi, i have made it to work with the SDM library, there is a Dere pin that we can trigger to enable the usage of max485, now the reall question is how can we include that in tasmota, would be awesome to make it work the same way.

#define DERE_PIN 4 //digital pin for control MAX485 DE/RE lines (connect DE & /RE together to this pin)

@gtortone
Copy link
Contributor Author

Hi @rflx18,
I did not use this serial implementation https://github.com/reaper7/SDM_Energy_Meter but TasmotaSerial developed by @arendst.

the pin you are reporting is available on RS485/RS422 adapter while there is not such pin in RS384/UART-TTL... btw this has to be included in TasmotaSerial library

@rflx18
Copy link

rflx18 commented May 23, 2018

sorry gtortone, this is out of my league :), is it possible to include that pin for tasmota porposes also?
im finding much more dificult to get a rs485 than a max485

@gtortone
Copy link
Contributor Author

gtortone commented May 23, 2018

I don't know TasmotaSerial library in depth... but take into account that following your request you need an additional pin (TX, RX, DERE) that on a Sonoff device is not always a simple thing...

@rflx18
Copy link

rflx18 commented May 23, 2018

i know that, im using a nodemcu or a wemos, and the goal of the tasmota is to use more than 3 gpoio :)
i will w8 for good news, thanx

@localhost61
Copy link
Contributor

@gtortone, just to make things clear, I own the same adapter as @rflx18 and the chip is really a Max485. The bad news is that it's not designed to work under 3.3V. So it's OK for a Arduino Pro Mini but not a Sonoff Dual R2. :-/

@localhost61
Copy link
Contributor

localhost61 commented Aug 27, 2018

Yes @gtortone , it's already in the pipe. ;-)

[Edit] Ordered here for 1.10€ and received yesterday (10 day later) and you're right IC's marking are erased

curzon01 pushed a commit to curzon01/Tasmota that referenced this pull request Sep 7, 2018
5.13.1a
* Add Eastron SDM120 energy meter (arendst#2694)
@localhost61
Copy link
Contributor

localhost61 commented Sep 8, 2018

@gtortone, your adapter is very interesting because it matches pin for pin the J2 header on a Sonoff Dual R2. Unfortunately I couldn't succeed to make it work "out of the box" on SDM120 and SDM230.
Even disconnected from the modbus, but fitted on the Dual R2 connector, the RX LED blinks every second, even if I invert RX pin and TX pin through the module configuration webpage.
Then guess I'll have to take the slow way, initiate at first my Eastron modules and study the ModBus protocol. :sight:

@gtortone
Copy link
Contributor Author

gtortone commented Sep 8, 2018

@localhost61 this is my configuration of SDM120 for Sonoff Basic:
image

I suggest you to double check speed of SDM module and speed inside Sonoff-Tasmota configuration file user_config.h (SDM120_SPEED or SDM630_SPEED)

@localhost61
Copy link
Contributor

localhost61 commented Sep 9, 2018

Thanks for the tips Gennaro! I did the same, SDM-TX on Serial In and SDM-RX on Serial Out, it's logical !
I had already thrown an eye on the SDM driver code and seen you didn't implement any new command to manage them from the console, I'll have to get a windows app and learn how to write proper settings in the 4X registers and check if everything is in order, 32 bit float values and CRC make it difficult to do that manually :-/ . I already have the USB to RS485 adapter for the job (and for monitoring too.)
Currently, my SDM120 both default to node 01 at 2400,8E1 and SDM230 to node 01 too at 9600,8N1 (this one can be setup on device manually use both buttons whereas the SDM120 needs a modbus master for that).
I'm aware I have to address them separately but my goal is to mount them as a bus and I may dedicate a WeMos D1 pro for them.

@localhost61
Copy link
Contributor

localhost61 commented Sep 11, 2018

Hi,
Unfortunately, it seems my adapter is broken, the SD3485 doesn't work properly.

  • When the adapter is only powered with 3.3V and other pins not connected, the pullup/pulldown make that the bus should be HiZ. It,'s not the case here, the 4k7 pullup on A+ doesn't pull the value to Vcc but only 2.24V
  • When the adapter is running on the Dual R2 and an other master is connected on the bus, with no slave and polling the bus each second, then the RxD Led should blink on the adapter, not only the TxD driven by Tasmota.
  • For those interested, here is a schematic I've reverse designed from the adapter:

adapter rs485 3v3

@localhost61
Copy link
Contributor

localhost61 commented Sep 13, 2018

Shame on me! The adapter pinout doesn't match the Dual R2. RX and TX are twisted.
It explains why RxD Led blinked and not the TxD one. Once crossed it works ^^.

  • It' seems that there is only one working option that is to map Tasmota SDM120Tx and SDM120Rx on the physical TxD and RxD pins, but they can be crossed, it acts the same. Other GPIO pins can be selected too but the SDM data won't appear on the main webpage, so it won't work.
  • Now I can see that a SDM120 consumes 15VAR, it's hudge ! But 0W active, that means nothing on the bill. (Power factor is 0.06 whereas a resistive load is 1.0)

@gtortone
Copy link
Contributor Author

@localhost61 I'm happy you solve your communication problem !
regarding pin selection this is strange because SDM120 code uses TasmotaSerial library that can be mapped on every GPIO pin...

@localhost61
Copy link
Contributor

localhost61 commented Sep 14, 2018

@gtortone :

SDM120 code uses TasmotaSerial library

maybe not when compiled with core 2.3.0 which defaults now in platformio.ini
[Edit]
In fact, after checking, I'm running 6.1.1.11 on latest core 2.4.2 and this is the main page:

Where two SDM120 are powered thru a SDM230 on the same bus at 9600,8N1 but with different ID:

imag0090

Here is how I connected the adapter:

imag0102 - working

imag0096 - modbus connection

@localhost61
Copy link
Contributor

@gtortone
I just downloaded latest build 6.2.1.3, compiled with old core 2.3.0 and uploaded OTA to this Dual R2.
It acts the same, same home page and 75SDM120Tx can be exchanged with 76SDM120Rx in the module configuration with no difference.

I would like to see if I can change the code in order to add a command to change the modbus slave target ID in order to monitor my three devices, that should be rather straightful.

@arendst
Copy link
Owner

arendst commented Sep 23, 2019

@localhost61 Xavier, just got myself a SDM230 and seeing how you hooked it up confirms my connection.

I see you do not use the Gnd of the RS485 interface. Is it not needed? I disconnected mine too and it seems to work just fine indeed.

I connected only a simple load of 15W so that's probably an issue but I see the Export Reactive value incrementing together with the Import Active and Total counters. I cannot explain this as I'm definitly not supplying power.

Edit1: Forget my Export Reactive question. As it is negative it is probably measured as export. Now I connected a 75W incandescant bulb and reactive power is now 0 (as expected) and Export Reactive stopped updating.

@localhost61
Copy link
Contributor

localhost61 commented Sep 23, 2019

I guess that Gnd may be used for long distance ModBus for the Shield, not used with a twisted pair
About exporting reactive energy I don't think there is an issue with the driver here, as it only reports the registers content... and the SDM230 display lets you see the same value ;-)
It seems weird when you monitor a simple load on the grid but it simply means that your load is mostly capacitive and then the meter consider that you export reactive power (sin(φ)<0)), with an inductive load like a drill machine or an old fashion neon with ballast it should increase the import reactive power counter.
With switching power supplies, when the current is not a pure sinusoid, there is a reactive part too but I don't know how to tell if it will be inductive or capacitive.

@localhost61
Copy link
Contributor

localhost61 commented Sep 23, 2019

I just tested with a vacuum cleaner. It's power factor is optimized at full power, but at minimal power, it's only 0.5 and I could verify that as an inductive load it increase import reactive energy counter. The export energy counter remains unchanged. I currently have a "capital" of 44kVAr in the export energy counter because my SDM230 was loaded 24/7 by 2 SDM120 that are seen as very highly capacitive loads.


I notice right now that there is a confusion in my translation, but maybe in the english version too, you tell me...
Power times a duration equates to an energy, all the D_POWERUSAGE strings are not power but energy counters. In French we don't say Power supply but Alimentation, meaning feeding so for us power is always in Watt (or maybe Horse Power, it depends ;-) ) but never in Wh :-(

@localhost61
Copy link
Contributor

I was wrong, D_POWERUSAGE strings are truly power values. The issue is only in regards to SDM220 specific IMPORT/EXPORT strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Type - Enhancement that will be worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants